package agents;

import game.constants.ReferenceAgent;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.Agent;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionDropObject;
import actions.ActionIncreaseLife;
import constants.Constants;



public class AgentCreateStarcraftObject extends Agent{
	
	ActionDropObject actionDrop;
	
	double contTime=0;
	SpetialFeature lifeIncreasePerSecond; 

	@Override
	public void initializeActionList() {
		actionDrop= new ActionDropObject();
		addAction(actionDrop);
		
	}

	@Override
	public void initializeSpecialFeatures() {
		
		lifeIncreasePerSecond= new SpetialFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_LIFE_INCREASE_PER_SECOND);
		addSpetialFeature(lifeIncreasePerSecond);
		
	}

	@Override
	public void initializeName() {
		name="agent Create Starcraft";
		
	}

	@Override
	public void initializeId() {
		id=ReferenceAgent.AGENT_CREATE_STARCRAFT_OBJECT;
		
	}

	@Override
	public void updateChild(WorldObject object, Universe universe, double time) {
		contTime+=time;
		if(contTime<1000){
			return;
		}
		contTime=0;
		for(WorldObject obj: object.getListObjects()){
			SpetialFeature isBuilding = obj.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_IS_BUILDING);
			if(isBuilding==null){
				continue;
			}
			if(isBuilding.getValue()==Constants.FALSE){
				continue;
			}
			
			SpetialFeature totalLife = obj.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_LIFE);
			SpetialFeature currentLife = obj.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_CURRENT_LIFE);
			if(currentLife==null || totalLife ==null){
				continue;
			}
			System.out.println("ando por aca1");
			if(currentLife.getValue()<totalLife.getValue()){
				System.out.println("ando por aca2");
				ActionIncreaseLife actionModify = new ActionIncreaseLife();
				actionModify.setSource(obj);
				actionModify.setTarget(obj);
				actionModify.setLifeToIncrease(lifeIncreasePerSecond.getValue());
				universe.setAction(actionModify);
				return;
			}
			actionDrop.setSource(object);
			actionDrop.setTarget(object);
			actionDrop.setObjectToDrop(obj);
			actionDrop.setOwner(object.getOwner());
			universe.setAction(actionDrop);
			//termine de contruir el objeto;
		}
		
	}
	
	

}
